package org.xg.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName ShowServlet
 * @date 2021/9/23 16:02
 **/
@WebServlet("/showServlet")
public class ShowServlet extends HttpServlet {
    private static final long serialVersionUID=1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer count = (Integer) getServletContext().getAttribute("count");
        resp.setContentType("text/html;charset=UTF-8");
        if(null!=count){
            resp.getWriter().write("<h3>该网站一共被访问了"+count+"次</h3>");
        }else {
            resp.getWriter().write("<h3>请向访问/countServlet</h3>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req,resp);
    }
}
